import { _decorator, Component, instantiate, Label, Node, Prefab } from 'cc';
import { reportInfo_SendHelp } from '../entity/reportInfo_SendHelp';
import { ArmyCountItem } from './ArmyCountItem';
import { Army } from '../entity/Army';
const { ccclass, property } = _decorator;

@ccclass('ArmyCount')
export class ArmyCount extends Component {
    @property(Label)
    tittle:Label
    @property(Node)
    layout:Node

    @property(Prefab)
    armyCountItem:Prefab

    start() {

    }

    setData(info: reportInfo_SendHelp) {
        this.setArmy(info.helpArmy)
    }

    setArmy(army:Army){
        let list = army.soldierList
        for(let item of list){
            let node = instantiate(this.armyCountItem)
            if(item.count == 0){
                continue
            }
            this.layout.addChild(node)
            node.getComponent(ArmyCountItem).setData(item)
        }
    }

    setTittle(str:string){
        this.tittle.string = str
    }
}


